import axios from 'axios';
import makeApi from './index';

const api = {
	create: '/message/advertisementDisplay/add',
	remove: '/message/advertisementDisplay/delete',
	detail: '/message/advertisementDisplay/detail',
	query: '/message/advertisementDisplay/list'
};

const services = makeApi(api);

services.create = async (data, onDownloadProgress) => {
	const params = new FormData();
	Object.keys(data).forEach(key => {
		if (key === 'file') {
			params.append(key, data[key], data[key].name);
		} else {
			params.append(key, data[key]);
		}
	});
	const res = await axios.post(api.create, params, {
		onDownloadProgress,
		headers: {
			Authorization: window.localStorage.getItem('access_token')
		}
	});
	return res.data;
};

const {
	create,
	remove,
	detail,
	query
} = services;

export {
	create,
	remove,
	detail,
	query
};

export default services;

